package day8;

import java.util.Scanner;

public interface interfaceA {
    int method(int n);
}

class ClassA implements interfaceA {

    @Override
    public int method(int n) {
        int num=0;
        for(int i=1;n>=i;i++){
            num=num+i;
        }
        return num;
    }
}

class ClassB implements interfaceA {

    @Override
    public int method(int n) {
        int num=1;
        for(int i=1;n>=i;i++){
            num=num*i;
        }
        return num;
    }
}

class TestInterfaceA{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入n的取值");
        int n=sc.nextInt();
        interfaceA obj=new ClassA();
        int add=obj.method(n);
        System.out.println(n+"的累加:"+add);
        obj=new ClassB();
        int Factorial=obj.method(n);
        System.out.println(n+"的阶乘:"+Factorial);
    }
}